package com.wowangz.cms.systemmanage.headbank.service;


import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;
import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.headbank.pojo.HeadBank;


public class HeadBankService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(HeadBankService.class);

	public void add(HeadBank headBank) throws ServiceException {
		try {
			this.getSqlSession().insert("HeadBank.insertHeadBank", headBank);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}
	
	public void delete(String ids) throws ServiceException {
		if (Strings.isNullOrEmpty(ids)) {
			return;
		}
		String[] temIds = ids.split(",");

		try {
			for (String id : temIds) {
				this.getSqlSession().delete("HeadBank.deleteHeadBank", id);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

	public void update(HeadBank headBank) throws ServiceException {
		try {
			this.getSqlSession().update("HeadBank.updateHeadBank", headBank);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

	public HeadBank findHeadBankById(String id) throws ServiceException {
		HeadBank headBank = null;
		try {
			headBank = this.getSqlSession().selectOne("HeadBank.findHeadBankById", id);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return headBank;
	}

	public List<HeadBank> query(HeadBank headBank) throws ServiceException {
		List<HeadBank> list = null;
		try {
			list = this.getSqlSession().selectList("HeadBank.queryHeadBank");
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return list;

	}

	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		Long countNum = null;
		try {
			countNum = this.getSqlSession().selectOne("HeadBank.queryHeadBankCount", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return countNum;
	}
	
	public boolean validationHeadBank(HashMap<String, Object> map) throws ServiceException {
		Long countNum = null;
		try {
			countNum = this.getSqlSession().selectOne("HeadBank.validationHeadBank", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		if(countNum != 0){
			return false;
		}else{
			return true;
		}
	}

	/**
	 * 查询记录集合
	 * 
	 * @param map
	 * @return
	 */
	public List<HeadBank> findResultList(HashMap<String, Object> map) throws ServiceException {
		List<HeadBank> list = null;
		try {
			 list = this.getSqlSession().selectList("HeadBank.queryHeadBankPage", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return list;
	}
	
	public HeadBank findHeadBankByDirectcode(HashMap<String, Object> map) throws ServiceException
	{
		HeadBank headbank = null;
		try {
			headbank = this.getSqlSession().selectOne("HeadBank.findHeadBankByDirectcode", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return headbank;
	}


}
